import {Button, DatePicker, Form, Input, Select} from 'antd';
import React from 'react';

const {Option} = Select;
const {RangePicker} = DatePicker;

interface LessonFilterProps {
  onFilterChange: (values: any) => void;
}

const LessonFilter: React.FC<LessonFilterProps> = ({onFilterChange}) => {
  const [form] = Form.useForm();

  const handleReset = () => {
    form.resetFields();
    onFilterChange({});
  };

  const handleFinish = (values: any) => {
    if (values?.startTime) {
      values.startTime = values.startTime.format('YYYY-MM-DDTHH:mm:ss')
    }
    if (values?.endTime) {
      values.endTime = values.endTime.format('YYYY-MM-DDTHH:mm:ss')
    }

    onFilterChange(values);
  };

  return (
    <Form form={form} layout="inline" onFinish={handleFinish}>
      <Form.Item name="licenseTypeId" label="驾照类型">
        <Select style={{width: 120}} allowClear>
          <Option value={1}>科目一</Option>
          <Option value={2}>科目二</Option>
          <Option value={3}>科目三</Option>
          <Option value={4}>科目四</Option>
        </Select>
      </Form.Item>

      <Form.Item name="courseType" label="课程类型">
        <Select style={{width: 120}} allowClear>
          <Option value={1}>科目一</Option>
          <Option value={2}>科目二</Option>
          <Option value={3}>科目三</Option>
          <Option value={4}>科目四</Option>
        </Select>
      </Form.Item>

      <Form.Item name="status" label="预约状态">
        <Select style={{width: 120}} allowClear>
          <Option value={1}>可预约</Option>
          <Option value={2}>预约上限</Option>
          <Option value={3}>不可预约</Option>
        </Select>
      </Form.Item>

      <Form.Item name="startTime" label="开始时间">
        <DatePicker format="YYYY-MM-DD HH:mm:ss"/>
      </Form.Item>

      <Form.Item name="endTime" label="结束时间">
        <DatePicker format="YYYY-MM-DD HH:mm:ss"/>
      </Form.Item>

      <Form.Item>
        <Button type="primary" htmlType="submit">
          搜索
        </Button>
        <Button style={{marginLeft: 8}} onClick={handleReset}>
          重置
        </Button>
      </Form.Item>
    </Form>
  );
};

export default LessonFilter;
